package com.yaozheng.vocationaltraining.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.bean.PKMorePersonPlayerStatusBean;
import com.yaozheng.vocationaltraining.bean.PKSaiKuangBean;
import com.yaozheng.vocationaltraining.utils.BitmapLoader;
import com.yaozheng.vocationaltraining.widget.CircleImageView;

import java.util.List;

/**
 * Created by moon on 2017/11/19.
 */

public class PKSaiKuangListAdapter extends BaseAdapter {
    private LayoutInflater mInflater;//
    private Context mContext;
    private BitmapLoader userBitmapLoader;

    private List<PKSaiKuangBean> data = null;

    private int selectedPosition = -1;

    public PKSaiKuangListAdapter(Context context,
                                           List<PKSaiKuangBean> data) {
        this.mInflater = LayoutInflater.from(context);
        this.mContext = context;
        this.data = data;
        userBitmapLoader = new BitmapLoader(Glide.with(context), R.drawable.user_img);
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(
                    R.layout.pk_saikuang_list_item, null);
            holder = new ViewHolder();

            holder.userAvatarImage = (CircleImageView) convertView
                    .findViewById(R.id.userAvatarImage);
            holder.desc_textview = (TextView) convertView
                    .findViewById(R.id.desc_textview);

            convertView.setTag(holder);//
        } else {
            holder = (ViewHolder) convertView.getTag();//
        }

        //加载图片
        userBitmapLoader.displayImage(data.get(position).getPlayerAvatar(), holder.userAvatarImage);
//        0	准备中
//        1	比赛中
//        2	正常结束
//        3	中途放弃
//        4	比赛取消
        if (data.get(position).getStatus() == 0){//0未准备 ， 1比赛中 ，2 正常结束 ，3放弃 ，4 取消
            holder.desc_textview.setText(data.get(position).getPlayerName()+"还未准备好。");
            holder.desc_textview.setTextColor(mContext.getResources().getColor(R.color.black));
        }else if (data.get(position).getStatus() == 1){
            holder.desc_textview.setText(data.get(position).getPlayerName()+"正在答题。");
            holder.desc_textview.setTextColor(mContext.getResources().getColor(R.color.black));
        }else if (data.get(position).getStatus() == 2){
            holder.desc_textview.setText(data.get(position).getPlayerName()+"已交卷。");
            holder.desc_textview.setTextColor(mContext.getResources().getColor(R.color.footer_bg_color));
        }else if (data.get(position).getStatus() == 3){
            holder.desc_textview.setText(data.get(position).getPlayerName()+"已弃赛。");
            holder.desc_textview.setTextColor(mContext.getResources().getColor(R.color.black));
        }else if (data.get(position).getStatus() == 4){
            holder.desc_textview.setText(data.get(position).getPlayerName()+"已取消。");
            holder.desc_textview.setTextColor(mContext.getResources().getColor(R.color.black));
        }

        return convertView;
    }

    public void setData(List<PKSaiKuangBean> data) {
        this.data = data;
    }

    public void setselectedPosition(int selectedPosition) {
        notifyDataSetChanged();;
    }

    class ViewHolder {
        CircleImageView userAvatarImage;
        TextView desc_textview;
    }
}
